package org.example.map;

import org.example.Stu;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class Student {
    private int id;
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Student(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public Student() {
    }

    public Student(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return id+"="+name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return id == student.id;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    public static void main(String[] args) {
        Map<Student,String> map = new HashMap<>();
        map.put(new Student(1,"zhangsan"),"北京");
        map.put(new Student(1,"zhangsan"),"郑州");
        Student stu1 = new Student(1,"zs");
        Student stu2 = new Student(1,"ls");
        System.out.println(stu1.equals(stu2));

//        Student stu1 = new Student(1,"zhangsan");
//        map.put(stu1,"北京");
//        map.put(stu1,"郑州");
        System.out.println(map.size());
    }
}
